package 字节流;

import java.io.*;

//创建文件夹
//读写
//拷贝
public class 编写方法拷贝文件夹 {
    public static void main(String[] args) throws Exception {
        copyDir(new File("H:/zhongtong"),new File("H:/zhongtong2"));
    }

    private static void copyDir(File srcDir, File destDir)throws Exception {
        File f = new File(destDir,srcDir.getName());
        f.mkdirs();

        for (File file:srcDir.listFiles()){
            if(file.isFile()){
                无返回值拷贝(file,new File(f,file.getName()));
            }else {
                copyDir(file,f);
            }
        }
    }


        public static void 无返回值拷贝(File srcFile, File destFile) throws Exception {
            //创建读写
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
            //拷贝
            byte[] data=new byte[1024];
            int len;

            while ((len=bis.read(data))!=-1){
                bos.write(data,0,len);
            }
            bis.close();
            bos.close();
        }
}
